package com.qxp.simplerpc.proxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

/**
 * @author qianxiaopeng
 */
@SuppressWarnings("unchecked")
public class CglibProxy extends CommonProxy {
    @Override
    public <T> T getProxy(Class<?> cls, String className,String beanName) {
        Enhancer enhancer = new Enhancer();
        enhancer.setInterfaces(new Class[]{cls});
        enhancer.setCallback((MethodInterceptor) (o, method, args, methodProxy) -> this.connect(cls,method, args,className,beanName));
        return (T) enhancer.create();
    }

    @Override
    public <T> T getProxy(Class<?> cls) {
        return this.getProxy(cls,null,null);
    }
}
